// 加载高德地图脚本
export async function loadAMapScript() {
  try {
    // 获取地图配置
    const configResponse = await fetch('/api/map/config');
    const { config } = await configResponse.json();
    
    // 获取 JS API URL
    const urlResponse = await fetch(`/api/map/js-url?plugins=${config.plugins.join(',')}`);
    const { url } = await urlResponse.json();
    
    // 加载地图脚本
    await loadScript(url);
    
    return true;
  } catch (error) {
    console.error('加载地图脚本失败:', error);
    throw error;
  }
}

// 加载脚本工具函数
function loadScript(url) {
  return new Promise((resolve, reject) => {
    const script = document.createElement('script');
    script.src = url;
    script.async = true;
    script.onload = resolve;
    script.onerror = reject;
    document.head.appendChild(script);
  });
} 